package com.juyu.miliao.api.controller;

import com.juyu.miliao.api.domain.vo.NewYearDayActivitySignInVo;
import com.juyu.miliao.api.domain.vo.PrizeInfoVo;
import com.juyu.miliao.api.rabbitMQ.PaySuccessRabbitMq;
import com.juyu.miliao.api.service.NewYearDayActivityService;
import com.juyu.miliao.common.constant.NewYearDayActivityRedisKey;
import com.juyu.miliao.common.exception.ConsumeRuntimeException;
import com.juyu.miliao.common.exception.IllegalParamException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 元旦活动控制器
 *
 * @author xuanqicheng
 * @create 2018-26-09:15
 */
@RestController
@CrossOrigin
@RequestMapping("/newYearDayActivity")
public class NewYearDayActivityController {

    @Autowired
    private NewYearDayActivityService newYearDayActivityService;

    @Autowired
    private PaySuccessRabbitMq paySuccessRabbitMq;

    /**
     * 查询用户信息
     */
    @GetMapping("/{userId}")
    public NewYearDayActivitySignInVo getNewYearDayActivityByUserId(@PathVariable("userId") Long userId){
        if(userId==null){
            throw new IllegalParamException("参数不正确");
        }
        return newYearDayActivityService.getNewYearDayActivityByUserId(userId);

    }

    @GetMapping("/list")
    public Object getList(){
        return newYearDayActivityService.getHostUserList();
    }

    /**
     * 签到
     * @param userId
     * @return
     */
    @PostMapping("/signin")
    public void getSignIn( Long userId){
        newYearDayActivityService.getSignIn(userId);
    }

    /**
     * 获取剩余抽奖次数
     * @param userId
     * @return
     */
    @GetMapping("/number/{userId}")
    public Object getNumbers(@PathVariable("userId") Long userId){
        return newYearDayActivityService.getNumbers(userId);
    }
    /**
     * 抽奖
     * @param userId
     * @param hostId
     * @return
     */
    @PostMapping("/luckdraw")
    public Object getLuckDraw(Long userId,Long hostId){
        if(userId==null||hostId==null){
            throw new IllegalParamException("传入参数不正确");
        }
        return newYearDayActivityService.getLuckDraw(userId,hostId);
    }

    @GetMapping("/wininfo")
    public List<String> getWinInfo(){
        return newYearDayActivityService.getWinInfo();
    }

//    @GetMapping("/test/{userId}")
//    public void test(@PathVariable("userId")Long userId){
//
//        paySuccessRabbitMq.setNewYearDayActivity(Long.toString(userId));
//
//    }
}
